"""
this is the base parser for html and json and other format
"""
import json
from bs4 import BeautifulSoup as bs
from requests import Session

class BaseParser(object):
    """
    base parser for parser requests content
    """
    def __init__(self, *args, **kwargs):
        """
        supply the way to query html
        :param args the first is content
        :param kwargs the key is content
        """
        if args:
            self.content = args[0]
        elif kwargs:
            self.content = kwargs.get('content', '')
        else:
            self.content = ''

    @property
    def to_html(self):
        """
        change content to beautifulsoup html
        """
        result = bs(self.content, 'lxml')
        return result

    @property
    def to_dict(self):
        """
        change content to dict
        """
        try:
            result = json.loads(self.content)
        except Exception as tmp:
            print(tmp)
            result = {}
        return result
